//
//  STCommentCell.m
//  YiYueHairdresser
//
//  Created by zhouzhouzhou on 2018/10/11.
//  Copyright © 2018年 YuYiLian. All rights reserved.
//

#import "STCommentCell.h"
#import "AnotherStarEvaluator.h"

@implementation STCommentCell

-(instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    return self;
}

-(void)setCommentWithData:(id)commentDic{
    if ([commentDic isKindOfClass:[STCommentInfoModel class]]) {
        commentModel = commentDic;
    }
    self.replayText.delegate = self;
    if (commentModel.reply.length) {
        self.replayText.editable = NO;
        self.replayText.text = commentModel.reply;
        self.backLab.text =commentModel.reply;
        self.backLab.textColor = [UIColor clearColor];
    }else{
        self.replayText.editable = YES;
        self.backLab.text =@"请输入您的回复";
        self.backLab.textColor = [UIColor lightGrayColor];
    }
    
    self.timerLab.text= [[commentModel.createtime substringFromIndex:5] substringToIndex:11];
    self.serNameLab.text= commentModel.serviceName;
    
    self.commentLab.text =[NSString stringWithFormat:@"评论:%@", commentModel.comment];
    [self.headImg sd_setImageWithURL:[NSURL URLWithString:commentModel.headImg] placeholderImage:[UIImage imageNamed:@"h-hairEg"]];
    self.headImg.layer.cornerRadius = self.headImg.frame.size.height/2;
    self.headImg.layer.masksToBounds = YES;
    self.replyBackView.layer.cornerRadius = 5;
    self.replyBackView.layer.masksToBounds = YES;

    if (_isOrderCommon) {
        self.nameLab.text= commentModel.serviceName;
        self.nameLab.textColor = [UIColor lightGrayColor];
        self.serNameLab.textColor = [UIColor clearColor];
        self.starBackView.hidden = YES;
        self.nameLeft.constant = 30;
        self.tiemrRight.constant = 30;
        self.headImg.hidden = YES;
        self.lineView.hidden = YES;
    }else{
        self.nameLab.text=commentModel.name;
    }
    
    self.replayText.delegate = self;
    [self setStarView];
    [self setImgCollectionView];
}


-(void)setStarView{
    AnotherStarEvaluator *starAllEva = [[AnotherStarEvaluator alloc] initWithFrame:CGRectMake(15,(self.starBackView.frame.size.height-28)/2, 121, 28)];
    //    starAllEva.delegate = self;
    starAllEva.enabled=NO;
    [starAllEva setCurrentValue:commentModel.level];
    [self.starBackView addSubview:starAllEva];
}

-(void)setImgCollectionView{
    self.imgHeight.constant = (ceil(commentModel.imgPaths.count/3.0))*45;
    if(!proCollectionView){
        self.imgBackView.bounds = CGRectMake(0, 0, CGRectGetWidth(self.imgBackView.frame), ceil(commentModel.imgPaths.count/3.0)*50);
        proCollectionView=[[STShowColListView alloc]initWithFrame:CGRectMake(0, 0, CGRectGetWidth(self.imgBackView.frame), ceil(commentModel.imgPaths.count/3.0)*45)];
        proCollectionView.alimentType = ZYHShowCollectionTypeAlimentRight;
        proCollectionView.cellSize = CGSizeMake(40, 40);
        proCollectionView.sectionInset = UIEdgeInsetsMake(0, 0, 0, 0);
        proCollectionView.showViewClassName = @"STProjectImgView";
        [self.imgBackView addSubview:proCollectionView];
    }
    proCollectionView.frame =CGRectMake(0, 0, CGRectGetWidth(self.imgBackView.frame), ceil(commentModel.imgPaths.count/3.0)*45);
    [proCollectionView setShowCollectionViewWithData:commentModel.imgPaths];
    
}


-(void)csScrollView:(SHChangeSizeScrollView*)scrollView detailView:(int)detailNum{
    if ([self.delegate respondsToSelector:@selector(commentCell:selImgNum:)]) {
        [self.delegate commentCell:self selImgNum:detailNum];
    }
}

- (BOOL)textView:(UITextView *)textView shouldChangeTextInRange:(NSRange)range replacementText:(NSString *)text{
    if ([text isEqualToString:@"\n"]){
        if ([self.delegate respondsToSelector:@selector(commentCell:replayCommentText:)]) {
            [self.delegate commentCell:self replayCommentText:self.replayText.text];
        }
        return NO;
    }
    return YES;
}

- (void)textViewDidChange:(UITextView *)textView{
    self.backLab.text = textView.text;
    if (textView.text.length>0) {
        self.backLab.textColor = [UIColor clearColor];
    }else{
        self.backLab.text =@"请输入您的回复";
        self.backLab.textColor = [UIColor lightGrayColor];
    }
}



@end
